package com.bluesky.jwf.component.validator;

import com.bluesky.jwf.component.StringField;

public class EmailValidator extends StringValidator {

	public EmailValidator() {

	}

	@Override
	public void init(String html) {

		super.init(html);
		setMessage("email");
	}

	@Override
	public void validate() {
		String s = stringField.getString();
		if (s == null || s.trim().isEmpty()) {
			setResult(true);
			return;
		}
		if (s.matches("\\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}\\b"))
			setResult(true);
		else
			setResult(false);

	}

	public static void main(String[] args) {

	}
}
